﻿<?php
class_exists('LogWriter') or require (dirname(__FILE__) . '/core/LogWriter.php');
class_exists('MerchantConfig') or require (dirname(__FILE__) . '/core/MerchantConfig.php');
class_exists('TrxException') or require (dirname(__FILE__) . '/core/TrxException.php');
class_exists('XMLDocument') or require (dirname(__FILE__) . '/core/XMLDocument.php');
class_exists('TrxResponse') or require (dirname(__FILE__) . '/core/TrxResponse.php');
class Result extends TrxException {
	private $iLogWriter = null;
	function __construct() {
	}
	public function init($aMessage) {
		$this->iLogWriter = new LogWriter();
		try {

			//1、还原经过base64编码的信息
			$tMessage = base64_decode($aMessage);


			MerchantConfig :: verifySignXML($tMessage);
			$tResponse = new TrxResponse($tMessage);

		} catch (TrxException $e) {
			$tResponse = new TrxResponse();
			if ($this->iLogWriter != null) {

			}
			$tResponse->initWithCodeMsg($e->getCode(), $e->getMessage());
		} catch (Exception $e) {
			$tResponse = new TrxResponse($tMessage);
			if ($this->iLogWriter != null) {

			}
			$tResponse->initWithCodeMsg(TrxException :: TRX_EXC_CODE_199, $e->getMessage());
		}

		return $tResponse;
	}
}
?>